package com.example.demo.service.impl;

import com.example.demo.annotation.Loggable;
import com.example.demo.enums.Level;
import com.example.demo.mapper.DogMapper;
import com.example.demo.model.Dog;
import com.example.demo.service.DogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class DogServiceImpl implements DogService {

//    DogMapper是一个接口，自动注入信息来自于DogMapper.xml
    @Autowired
    private DogMapper dogMapper;



    @Override
//    @Loggable(message = "Retrieving dog from DB", level = Level.DEBUG)
    public Dog selectByID(Integer id)
    {
       return dogMapper.selectByID(id);
    }

    /**
     * 添加异常后事务会执行失败，不添加则会正常执行
     * @param dog
     * @return
     */
    @Override
//    @Transactional
    public Integer addDog(Dog dog) {
       Integer result=dogMapper.addDog(dog);
       Integer errorCase=10/0;
       System.out.println("10/0 get:"+errorCase);
       return result;
//        throw new RuntimeException();
//        return result;
//        return dogMapper.addDog(dog);
    }
}
